<?php
unset($Module);
include '../Module/GalleryModule.php';
$Module=new GalleryModule();

?>
<div class="id-list-item-about" style="">
    <div class="mybutton icon disable tooltip" title="Trở Về">
        <div>
            <img src="./images/icon/left1.png"/><span>Trở Về</span>
        </div>
    </div>
    <div class="mybutton icon spaceright tooltip"
        title="Tải Lại Trang"
        onclick="loadhtml('./Controller/?AUnit=10_gallery',$('#box-content'));">
        <div><img src="./images/icon/arrow_refresh1.png"/><span>Tải Lại</span></div>
    </div>
    <div class="clear"></div>
    <div style="height: 40px;width: 100%;text-align: center">
        <h1>Quản Lý Album Ảnh</h1>
    </div>
    <table style="width:700px;margin: 8px" class="id-table-manage dt">
        <tr>
            <th class="_tal">Mã Số</th>
            <th class="_tal">Tên Album</th>
            <th class="_tal">Tổng Số Ảnh</th>
            <th class="_tal">Insert</th>
            <th class="_tal">Update</th>
            <th class="_tal" style="min-width: 120px">#</th>
        </tr>
        <tr>
            <td colspan="5">
                <div class="_input-label">
                    <div class="input">
                        <input type="text" id="txtalbum_name" placeholder="Nhập Tên Album Mới" value=""/>
                        <div class="label">
                            <label>Album Mới</label>
                            <div class="warning-16 tooltip hover50" title="Nhập Tên Album Mới."></div>
                        </div>
                    </div>
                </div>
            </td>
            <td>
                <div class="_buttonr icon16 _button-purple _btnfix hover50" 
                     onclick="addalbum();"
                     >
                    <img src="./images/icon/addg.png">
                        <span>Thêm</span>
                </div>
                
            </td>
        </tr>
        <?
        
        $dt=$Module->gets();
        if($dt==null){
            echo "<tr><td colspan=6>Dữ Liệu Trống.</td></tr>";

        }else foreach ($dt as $row){
            if($row["image"]) $small_img=$row["image"];
            if($row["smallimage"]) $small_img=$row["smallimage"];
            
        ?>
        <tr class="id-row-head-<?=$row["id"]?>" >
            <td><?=$row["id"]?></td>
            <td onclick=""><?=$row["album"]?></td>
            <td><?=$row["amount"]?></td>
            <td><?=$row["insert"]?></td>
            <td><?=$row["update"]?></td>
            <td class="">
                <?
                if(isset($row["delete"])){
                ?>

                <span style="color:red">Xóa lúc <?=$row["delete"]?></span>
                <div class="icon16 hover50 tooltip" title="Khôi Phục" onclick="restorealbum('<?=$row["id"]?>');">
                        <img src="./images/icon/gtk_undelete.png"/>
                </div>
                <?
                }
                if($row["lock"])
                        echo "<img class='tooltip' src='./images/icon/16/locked.png' title='This item is locked'/>";
                ?>
                <span class="action">
                    <?
                    if(!isset($row["delete"]) && !$row["lock"]){
                    ?>
                    <div class="icon16 hover50 tooltip" title="Xóa" onclick="deletealbum('<?=$row["id"]?>');">

                        <img src="./images/icon/16/edit_delete.png"/>
                    </div>
                    <div class="icon16 hover50 tooltip" title="Chỉnh Sửa" onclick="loadhtml('Controller/?AUnit=11_gallery_detail&id=<?=$row["id"]?>',$('#box-content'));">

                        <img src="./images/icon/16/document_edit.png"/>
                    </div>
                    <?
                    }
                    
                    
                    ?>
                </span>
            </td>
        </tr>

        <?
        }
        unset($dt);
        ?>
    </table>
    
    <div style="clear: both"></div>
<!--    <div class="mybutton icon disable tooltip" title="Back"><div><img src="./images/icon/left1.png"/><span>Back</span></div></div>
    <div class="mybutton icon spaceright tooltip"
         title="Reload"
         onclick="loadhtml('./Controller/?AUnit=06_product',$('#content_product'));"><div><img src="./images/icon/arrow_refresh1.png"/><span>Reload</span></div></div>
    <div class="mybutton icon disable tooltip"
         title="Save"
         ><div><img src="./images/icon/media_floppy_green.png"/><span>Save</span></div></div>
    <div class="mybutton icon tooltip" onclick="loadproductdetail(null);"
         title="New"
         ><div><img src="./images/icon/addg.png"/><span>Add</span></div></div>

    <div style="clear: both"></div>-->
   
    <script>
        
        $(document).ready(function(){
            $(".tooltip").tipTip({defaultPosition:"top", edgeOffset: 10});
            
        });
        function addalbum(){
            if(!_FcheckFilled($("#txtalbum_name").val())){$("#txtalbum_name").focus();return;}
            var surl="./Controller/";
            var sdata={
                    "controller":"GalleryController",
                    "action":"add",
                    "name":$("#txtalbum_name").val()
            };
            jQuery.ajax({
                    type:"POST", 
                    data:sdata, 
                    dataType:"text", 
                    url:surl, 
                    success: function (data){
                        if(data=="true"){
                            showmsg("Thành Công.",2000);
                            loadhtml('Controller/?AUnit=10_gallery',$('#box-content'));
                        }else{
                            showerrorbox(null,data);
                        }

                    },
                    error: function (xhr, ajaxOptions, thrownError){
                            showerrorbox(null,"<b>Status</b>:"+xhr.status+"<br/><b>ThrownError</b>:"+thrownError,5000);

                    }
            });
        }
        function restorealbum(id){
            if(!confirm("Bạn muốn khôi phục album?")) return;
            var surl="./Controller/";
            var sdata={
                    "controller":"GalleryController",
                    "action":"restore",
                    "id":id
            };
            jQuery.ajax({
                    type:"POST", 
                    data:sdata, 
                    dataType:"text", 
                    url:surl, 
                    success: function (data){
                        if(data=="true"){
                            showmsg("Đã Khôi Phục.",2000);

                            var str="<span class=\"action\">";
                            str+="      <div class=\"icon16 hover50 tooltip\" title=\"Xóa\" onclick=\"deletealbum('"+id+"');\">";
                            str+="          <img src=\"images/icon/16/edit_delete.png\"/>";
                            str+="      </div>";
                            str+="      <div class=\"icon16 hover50 tooltip\" title=\"Chỉnh Sửa\" onclick=\"loadhtml('Controller/?AUnit=11_gallery_detail&id="+id+"',$('#box-content'));\">";
                            str+="          <img src=\"images/icon/16/document_edit.png\"/>";
                            str+="      </div>";
                            str+="   </span>";
                            $(".id-row-head-"+id).find("td:last-child").html(str);
                        }else{
                            showerrorbox(null,data);
                        }

                    },
                    error: function (xhr, ajaxOptions, thrownError){
                            showerrorbox(null,"<b>Status</b>:"+xhr.status+"<br/><b>ThrownError</b>:"+thrownError,5000);

                    }
            });
        }
        function deletealbum(id){
            if(!confirm("Bạn muốn xóa Album?")) return;
            var surl="./Controller/";
            var sdata={
                    "controller":"GalleryController",
                    "action":"delete",
                    "id":id
            };
            jQuery.ajax({
                    type:"POST", 
                    data:sdata, 
                    dataType:"text", 
                    url:surl, 
                    success: function (data){
                        if(data=="true"){
                            showmsg("Đã Xóa Album.",2000);
                            var str="<span style=\"color:red\">Đã Xóa</pan>";
                            str+="   <div class=\"icon16 hover50 tooltip\" title=\"Khôi Phục\" onclick=\"restorealbum('"+id+"');\">";
                            str+="      <img src=\"images/icon/gtk_undelete.png\"/>";
                            str+="   </div>";
                            $(".id-row-head-"+id).find("td:last-child").html(str);

                        }else{
                            showerrorbox(null,data);
                        }

                    },
                    error: function (xhr, ajaxOptions, thrownError){
                            showerrorbox(null,"<b>Status</b>:"+xhr.status+"<br/><b>ThrownError</b>:"+thrownError,5000);

                    }
            });
        }
    </script>
</div>
            

<?
unset($Module);
?>
